<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="请输入1~100的数字" v-model="n">
  <button @click="guess">猜吧</button>
  <h3>小提示：{{msg}}</h3>
</template>

<script setup>
  import {ref} from "vue";

  let num = parseInt(Math.random()*100)+1;
  console.log(num);
  const n = ref('');
  const msg = ref('');
  let count = 0;
  const guess = () => {
    count++;
    if(n.value>num){
      msg.value='猜大了';
    }else if(n.value<num){
      msg.value='猜小了';
    }else {
      msg.value='恭喜你猜了'+count+'次就对了！'
    }
  }
</script>

<style scoped>

</style>